package com.mcxx.convert;

import com.mcxx.modules.miniSalvation.family.entity.OrderInHouseEntity;
import com.mcxx.modules.miniSalvation.order.dto.NoticeBoardDTO;
import com.mcxx.modules.miniSalvation.order.dto.OrderApproveDTO;
import com.mcxx.modules.miniSalvation.order.dto.OrderInHouseDTO;
import com.mcxx.modules.miniSalvation.order.dto.OrderReviewDTO;
import com.mcxx.modules.miniSalvation.order.entity.NoticeBoardEntity;
import com.mcxx.modules.miniSalvation.order.entity.OrderDetailEntity;
import com.mcxx.modules.temporary.order.dto.TmpAuditDTO;
import com.mcxx.modules.temporary.order.dto.TmpOrderStateVerifyDTO;
import com.mcxx.modules.temporary.order.entity.TmpOrderDetailEntity;
import com.mcxx.modules.temporary.order.entity.TmpOrderEntity;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import org.springframework.beans.BeanUtils;

import java.util.Date;

public class OrderConvert {

    public static OrderInHouseEntity convertOrderInHouseEntity(OrderInHouseDTO inhouseDTO) {
        OrderInHouseEntity inHouseEntity = new OrderInHouseEntity();
        BeanUtils.copyProperties(inhouseDTO, inHouseEntity);
        inHouseEntity.setUpdateTime(new Date());
        return inHouseEntity;
    }


    public static OrderDetailEntity convertOrderDetailEntity(OrderReviewDTO orderReviewDTO, UserAccountVo userAccountVo){
        OrderDetailEntity orderDetailEntity = new OrderDetailEntity();
        BeanUtils.copyProperties(orderReviewDTO, orderDetailEntity);

        orderDetailEntity.setId(orderReviewDTO.getOrderDetailId());
        orderDetailEntity.setCheckDate(new Date());
        orderDetailEntity.setOperator(userAccountVo.getUsername());
        orderDetailEntity.setCreateBy(userAccountVo.getUserId());
        orderDetailEntity.setOrgId(userAccountVo.getOrgId());
        return orderDetailEntity;
    }


    public static TmpOrderDetailEntity convertOrderDetailEntity(TmpAuditDTO tmpAuditDTO, UserAccountVo userAccountVo,String checkType){
        TmpOrderDetailEntity orderDetailEntity = new TmpOrderDetailEntity();

        BeanUtils.copyProperties(tmpAuditDTO, orderDetailEntity);
        if(!CommonUtil.invalidArgs(tmpAuditDTO.getOrderDetailId())){
            orderDetailEntity.setId(tmpAuditDTO.getOrderDetailId());
        }
        orderDetailEntity.setCheckDate(new Date());
        orderDetailEntity.setOperator(userAccountVo.getUsername());
        orderDetailEntity.setCreateBy(userAccountVo.getUserId());
        orderDetailEntity.setOrgId(userAccountVo.getOrgId());
        orderDetailEntity.setCheckType(checkType);
        return orderDetailEntity;
    }


    public static NoticeBoardEntity convertNoticeBoardEntity(NoticeBoardDTO noticeBoardDTO){
        NoticeBoardEntity noticeBoardEntity = new NoticeBoardEntity();
        noticeBoardEntity.setBatchNo(noticeBoardDTO.getBatchNo());
        noticeBoardEntity.setUserAreaLevel(noticeBoardDTO.getUserAreaLevel());
        noticeBoardEntity.setStartDate(noticeBoardDTO.getStartDate());
        noticeBoardEntity.setState(noticeBoardDTO.getState());
        noticeBoardEntity.setBusinessType(noticeBoardDTO.getBusinessType());
        noticeBoardEntity.setStandType(noticeBoardDTO.getStandType());
        noticeBoardEntity.setAreaCode(noticeBoardDTO.getAreaCode());
        noticeBoardEntity.setOrgId(noticeBoardDTO.getOrgId());
        noticeBoardEntity.setRemark(noticeBoardDTO.getRemark());
        noticeBoardEntity.setCreateTime(new Date());
        noticeBoardEntity.setPayWay(noticeBoardDTO.getPayWay());
        noticeBoardEntity.setId(noticeBoardDTO.getBatchId());
        noticeBoardEntity.setParentId(noticeBoardDTO.getParentId());
        noticeBoardEntity.setNoticeType(noticeBoardDTO.getNoticeType() == null ? "1" : noticeBoardDTO.getNoticeType());
        noticeBoardEntity.setUserId(noticeBoardDTO.getUserId());
        return  noticeBoardEntity;
    }


    public static OrderDetailEntity convertOrderDetailEntity(OrderApproveDTO orderApproveDTO, UserAccountVo userAccountVo){
        OrderDetailEntity orderDetailEntity = new OrderDetailEntity();

        orderDetailEntity.setOrderId(orderApproveDTO.getOrderId());
        orderDetailEntity.setCheckOpinion(orderApproveDTO.getApprovalOpinion());
        orderDetailEntity.setCheckPeople(orderApproveDTO.getApproverName());
        orderDetailEntity.setBusinessStatus("04");

        orderDetailEntity.setCheckDate(new Date());
        orderDetailEntity.setOperator(userAccountVo.getUsername());
        orderDetailEntity.setCreateBy(userAccountVo.getUserId());
        orderDetailEntity.setOrgId(userAccountVo.getOrgId());
        orderDetailEntity.setCheckResult(orderApproveDTO.getApprovalResult());

        orderDetailEntity.setBusinessStatus(Constant.RemarkOperType.COUNTY);
        orderDetailEntity.setCheckType(Constant.CheckDatailStatus.Pi);

        return orderDetailEntity;
    }


    public static TmpOrderEntity convertOrder(TmpAuditDTO tmpAuditDTO, TmpOrderStateVerifyDTO orderState){
        TmpOrderEntity orderEntity = new TmpOrderEntity();
        orderEntity.setId(tmpAuditDTO.getOrderId());
        orderEntity.setBizState(orderState.getNextBizState());
        orderEntity.setState(orderState.getNextState());
        orderEntity.setSalvMoney(tmpAuditDTO.getSalvMoney());
        orderEntity.setStartMonth(tmpAuditDTO.getRescueyears());
        orderEntity.setEndMonth(tmpAuditDTO.getRescueyears());
        orderEntity.setSalvType(tmpAuditDTO.getSalvType());
        orderEntity.setPayWay(tmpAuditDTO.getPayWay());
        orderEntity.setSaveMemberNumber(tmpAuditDTO.getSaveMemberNumber());
        orderEntity.setOnethingCheckType(tmpAuditDTO.getOnethingCheckType());
        return orderEntity;
    }
}
